package com.ocom.human.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.human.EntityMsgYkmConfig;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.human.dao.IDaoMsgYkmConfig;
import com.ocom.human.service.MsgYkmConfigService;
import com.ocom.mysql.aspect.DataSourceAspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MsgYkmConfigServiceImpl extends ServiceImpl<IDaoMsgYkmConfig, EntityMsgYkmConfig> implements MsgYkmConfigService{

    @Autowired
    private IDaoMsgYkmConfig daoMsgYkmConfig;

    @DataSourceAspect(type= DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public List<EntityMsgYkmConfig> GetMsgYkmConfigList(Long comId) {
        QueryWrapper<EntityMsgYkmConfig> query = Wrappers.query();
        query.eq("com_id",comId);
        return daoMsgYkmConfig.selectList(query);
    }

    @DataSourceAspect(type= DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    @Override
    public void AddMsgYkmConfig(Long comId, List<EntityMsgYkmConfig> objects) {
        QueryWrapper<EntityMsgYkmConfig> query = Wrappers.query();
        query.eq("com_id",comId);
        daoMsgYkmConfig.delete(query);
        this.saveBatch(objects);
    }
}
